<template>
  <!-- 服务管理 -->
  <div class="innerPageTable-box-OneTwo value-set-list-wrap innerPageTable-out-flex">
    <!--  <div>88:{{this.searchForm.code}}</div> -->
    <!-- 搜索区域 -->
    <p class="title">历史季度进度更新记录</p>
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="serviceForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item :label="'季度：'">
          <Select filterable clearable v-model="searchForm.taskQuarter">
            <Option v-for="item in taskQuarterList" :value="item.value" :key="item.value">{{ item.value }}</Option>
          </Select>
        </Form-item>
        <Form-item :label="'当前状态：'">
          <Select v-model="searchForm.currentStatus" clearable>
            <Option v-for="item in currentStatusList" :value="item.value" :key="item.value">{{ item.text }}</Option>
          </Select>
        </Form-item>

        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">
          <RPButton optType="search" ref="search" @click="searchValueSet()" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable v-if="showTable" ref="valueSetTable" :config="pageTableConfig"> </InnerPageTable>
  </div>
</template>

<script>
import { planDataColumns } from './columns'
import planEditAndDetail from '../planEditAndDetail.vue'
import coverApi from '@/api/cover.js'
// 根据不同环境域名映射的常量
// const hostAndVariablesMap = {
//   'crinfo-sit.test.crcloud.com': {
//     'client_id': 'shate-web-sit',
//     'tenant': 'itshare-sit',
//   },
//   'crinfo-uat.test.crcloud.com': {
//     'client_id': 'it-share-uat',
//     'tenant': 'itshare-uat',
//   },
//   'crinfo.crcloud.com': {
//     'client_id': 'SHARE_WEB',
//     'tenant': 'IT_SHARE_DEVELOP',
//   }
// }
export default {
  name: 'historyUpdateList',
  data() {
    return {
      authorization: '',
      searchForm: {
        taskQuarter: '',
        currentStatus: ''
      },
      taskQuarterList: [
        { text: '2022-1', value: '2022-1' },
        { text: '2022-2', value: '2022-2' },
        { text: '2022-3', value: '2022-3' },
        { text: '2022-4', value: '2022-4' },
        { text: '2023-1', value: '2023-1' },
        { text: '2023-2', value: '2023-2' },
        { text: '2023-3', value: '2023-3' },
        { text: '2023-4', value: '2023-4' },
        { text: '2024-1', value: '2024-1' },
        { text: '2024-2', value: '2024-2' },
        { text: '2024-3', value: '2024-3' },
        { text: '2024-4', value: '2024-4' },
        { text: '2025-1', value: '2025-1' },
        { text: '2025-2', value: '2025-2' },
        { text: '2025-3', value: '2025-3' },
        { text: '2025-4', value: '2025-4' }
      ],
      currentStatusList: [
        { text: '未启动', value: '未启动' },
        { text: '正常进行', value: '正常进行' },
        { text: '超额推进', value: '超额推进' },
        { text: '延期进行', value: '延期进行' },
        { text: '已完成', value: '已完成' },
        { text: '--', value: '--' }
      ],
      pageTableConfig: {
        resource: [],
        columns: planDataColumns.bind(this)(),
        autoFirst: true, //默认 就是 false, 要配置在这里
        isPage: false
      },
      resourceList: [],
      tableList: [],
      showTable: false
    }
  },
  created() {
    let params = this.$route.params
    this.bindId = params.bindId || ''
    coverApi.getHistoryUodateList({ bindId: this.bindId }).then(res => {
      this.resourceList = res.data.data
      this.pageTableConfig.resource = [].concat(this.resourceList)
      this.showTable = true
    })
    // if (localStorage.Authorization) {
    //   this.authorization = localStorage.Authorization
    //   coverApi.getHistoryUodateList({bindId: this.bindId, token: 'Bearer ' + localStorage.Authorization }).then(res => {
    //     this.resourceList = res.data.data;
    //     this.pageTableConfig.resource = [].concat(this.resourceList)
    //     this.showTable = true
    //   })
    // } else {
    //   let query = this.$route.query
    //   let bpmp3token = query.token || ''
    //   let bpmpUser = bpmp3token ? JSON.parse(window.atob(bpmp3token)) : {}
    //   let variables = hostAndVariablesMap[location.hostname]
    //   // 调用中台接口使用bpmtoken换取中台token
    //   if (bpmpUser.Uid && bpmp3token && variables) {
    //     coverApi.getOauthTokenByBpmToken({
    //       bpmp3token,
    //       client_id: variables.client_id,
    //       // grant_type---固定值：password
    //       grant_type: 'password',
    //       tenant: variables.tenant,
    //       username: bpmpUser.Uid
    //     }).then(res => {
    //       if (res.data.success === false) {
    //         this.$Message.error({
    //           content: '登录信息已失效，请刷新页面重试',
    //           duration: 3
    //         })
    //       } else {
    //         // {
    //         //   "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJEQURQVEVTVDIiLCJyZWFsX25hbWUiOiJMREFQ5rWL6K-V6LSm5Y-3MiIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUiIsIlJPTEVfQ09NTU9OIl0sImNsaWVudF9pZCI6Iml0LXNoYXJlLXVhdCIsImtleV92ZXJzaW9uIjoiMDAxIiwidXNlcl9pZCI6IjA4YzNhZTJmMGNkNjU3YTYzZWY4ZDFkNDIwOWQ4ODBlIiwib3JnX2lkIjoiZjZhYzA0NGM4ODFlZDQ0Njk3Y2Q5ZDQ2MDM3NjU5MTAiLCJzY29wZSI6WyJub25lIl0sIm5pY2tfbmFtZSI6IkxEQVDmtYvor5XotKblj7cyIiwidXNlcl9hY2NvdW50IjoiREFEUFRFU1QyIiwiZXhwIjoxNzA2NTU2NjU3LCJvcmdfbmFtZSI6Iml05YWx5Lqr5rK755CGIiwianRpIjoiWnNMVktfRVlxYlVhRngyaFBqcmxUQ1EyZGdRIiwidGVuYW50X2NvZGUiOiJpdHNoYXJlLXVhdCJ9.xxh7U0U9igJK8ZE_Vwtph2F_vguxuAjf8DeAiy6dD88",
    //         //   "token_type": "bearer",
    //         //   "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJEQURQVEVTVDIiLCJyZWFsX25hbWUiOiJMREFQ5rWL6K-V6LSm5Y-3MiIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUiIsIlJPTEVfQ09NTU9OIl0sImNsaWVudF9pZCI6Iml0LXNoYXJlLXVhdCIsImtleV92ZXJzaW9uIjoiMDAxIiwidXNlcl9pZCI6IjA4YzNhZTJmMGNkNjU3YTYzZWY4ZDFkNDIwOWQ4ODBlIiwib3JnX2lkIjoiZjZhYzA0NGM4ODFlZDQ0Njk3Y2Q5ZDQ2MDM3NjU5MTAiLCJzY29wZSI6WyJub25lIl0sIm5pY2tfbmFtZSI6IkxEQVDmtYvor5XotKblj7cyIiwiYXRpIjoiWnNMVktfRVlxYlVhRngyaFBqcmxUQ1EyZGdRIiwidXNlcl9hY2NvdW50IjoiREFEUFRFU1QyIiwiZXhwIjoxNzA2NTU2NjU3LCJvcmdfbmFtZSI6Iml05YWx5Lqr5rK755CGIiwianRpIjoibDJjbHd3UWRhd3lQcFF5bTd3c2VOTTYtclU0IiwidGVuYW50X2NvZGUiOiJpdHNoYXJlLXVhdCJ9.h3exi0uNdJQXtLbelAZBO8k5Kx8oG3ysiWxEX4r9C7w",
    //         //   "expires_in": 59999,
    //         //   "scope": "none",
    //         //   "key_version": "001",
    //         //   "user_id": "08c3ae2f0cd657a63ef8d1d4209d880e",
    //         //   "user_name": "DADPTEST2",
    //         //   "org_id": "f6ac044c881ed44697cd9d4603765910",
    //         //   "nick_name": "LDAP测试账号2",
    //         //   "user_account": "DADPTEST2",
    //         //   "real_name": "LDAP测试账号2",
    //         //   "org_name": "it共享治理",
    //         //   "tenant_code": "itshare-uat",
    //         //   "jti": "ZsLVK_EYqbUaFx2hPjrlTCQ2dgQ"
    //         // }
    //         let token = res.data.access_token
    //         this.authorization = token
    //         coverApi.getHistoryUodateList({ bindId: this.bindId, token: 'Bearer ' + token }).then(res => {
    //           this.resourceList = res.data.data;
    //           this.pageTableConfig.resource = [].concat(this.resourceList)
    //           this.showTable = true
    //         })
    //       }
    //     })
    //   }
    // }
  },
  methods: {
    goDetail(row) {
      new this.$sidelipPage(
        planEditAndDetail,
        {
          props: {
            id: row.id || '',
            disabledPage: true,
            hiddenBtnGroup: true,
            authorization: this.authorization,
            dataStatus: Number(row.wfStatus) || 3
          }
        },
        data => {
          data && this.searchValueSet()
        }
      )
    },

    searchValueSet() {
      this.pageTableConfig.resource = this.resourceList.filter(item => {
        let flag = true
        if (this.searchForm.taskQuarter && item.taskQuarter !== this.searchForm.taskQuarter) {
          flag = false
        }
        if (this.searchForm.currentStatus && item.currentStatus !== this.searchForm.currentStatus) {
          flag = false
        }
        return flag
      })
    }
  },
  directives: {}
}
</script>
<style>
.main {
  height: 100%;
}
.ivu-layout {
  height: 100%;
}
</style>
<style lang="less" scoped>
/deep/.table-bar button:last-child {
  color: #ffffff;
  background-color: #ff6f4b;
  border-color: #ff6f4b;
}

/deep/ .handle-cus {
  font-size: 18px;
  &:hover {
    color: #ff6f4b;
    cursor: pointer;
  }
}
.title {
  padding: 10px;
  font-size: 16px;
  border-bottom: 1px solid #eee;
  margin-bottom: 10px;
}
</style>
